home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / TransparencyTrickUtils.java < prev    next >
Text File  |  1998-10-20  |  5KB  |  129 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.*;
  4.  
  5. //    02/03/97    LAB    Fixed a type-o in the NOTE below.
  6. //     02/15/97    RKM    Put gc and runFinalization in paintComponent
  7. //     02/16/97    RKM    Changed paint call to update as per David E's suggestion
  8. //     07/13/97    LAB    Deprecated because it's not needed in JDK 1.1.
  9. //                    Added version and author tags.
  10.  
  11. //
  12. // NOTE:    If you use this routine, you need to implement TransparencyTrick.
  13. //            Otherwise intersecting your component with another componet that uses
  14. //            these routines will result in a lock up
  15. //
  16.  
  17. /**
  18.  * @deprecated
  19.  * This is no longer used or supported as of JDK 1.1 since the new JDK allows
  20.  * "Lightweight" components which are "Transparent" in nature by default.
  21.  *
  22.  * This class implements a painting method that is used to simulate transparent
  23.  * Components. If you use this class you also need to implement TransparencyTrick.
  24.  * Otherwise visually intersecting your Component with another Component that uses
  25.  * these routines will result in a lock up.
  26.  *
  27.  * @version 1.1, July 14, 1997
  28.  * @author Symantec
  29.  */
  30. public class TransparencyTrickUtils
  31. {
  32.     private TransparencyTrickUtils() {
  33.     }
  34.  
  35.     //
  36.     // Implements transparency the bast we can under AWT
  37.     //
  38.     /**
  39.      * @deprecated
  40.      * This is no longer used or supported as of JDK 1.1 since the new JDK allows
  41.      * "Lightweight" components which are "Transparent" in nature by default.
  42.      *
  43.      * This method implements the painting of transparent components.
  44.      * It does this by painting the component's parent and all the other
  45.      * components that intersect with the invisible component.
  46.      * @param drawingComponent the invisible component "being drawn"
  47.      * @param g the graphics context to use for drawing
  48.      */
  49.     public static void paintComponentsBehind
  50.             (Component    drawingComponent,
  51.              Graphics    g)
  52.     {
  53.         Rectangle myBounds = drawingComponent.bounds();
  54.  
  55.         //First fill my background with myParent
  56.         Container myParent = drawingComponent.getParent();
  57.         paintComponent(drawingComponent, (Component)myParent, myBounds, g);
  58.  
  59.         //Now draw any intersecting components
  60.         Component[] list = myParent.getComponents();
  61.         for (int i = 0; i < list.length; ++i) {
  62.             Component c = list[i];
  63.             if (c != drawingComponent)
  64.                 paintComponent(drawingComponent, c, myBounds, g);
  65.         }
  66.     }
  67.  
  68.     //
  69.     // A utility of paintComponentsBehind
  70.     //
  71.  
  72.     /**
  73.      * @deprecated
  74.      * This is no longer used or supported as of JDK 1.1 since the new JDK allows
  75.      * "Lightweight" components which are "Transparent" in nature by default.
  76.      *
  77.      * This method paints one component that intersects with the invisible
  78.      * component. It is a utility routine called by paintComponentsBehind().
  79.      * @param drawingComponent the invisible component "being drawn"
  80.      * @param intersectingComponent the component that intersects the drawingComponent
  81.      * @param myBounds the bounds of the invisible component
  82.      * @param g the graphics context to use for drawing
  83.      * @see #paintComponentsBehind
  84.      */
  85.     public static void paintComponent
  86.             (Component    drawingComponent,
  87.              Component    intersectingComponent,
  88.              Rectangle    myBounds,
  89.              Graphics    g)
  90.     {
  91.         //If it's an invisible button, don't draw this component (avoid recursion)
  92.         if (intersectingComponent instanceof TransparencyTrick)
  93.             return;
  94.  
  95.         //Make certain intersectingComponent really does intersect us
  96.         Rectangle icBounds = intersectingComponent.bounds();
  97.         if (icBounds.intersects(myBounds)) {
  98.             Image img = drawingComponent.createImage(icBounds.width, icBounds.height);
  99.             if (img != null) {
  100.                 //Get the graphics object representing the image
  101.                 Graphics imageGraphics = img.getGraphics();
  102.                 if ( imageGraphics.getClip() == null )
  103.                     imageGraphics.clipRect( 0, 0, icBounds.width, icBounds.height );
  104.                 if (imageGraphics != null) {
  105.                     //Draw the intersecting component into the offscreen image
  106.                     intersectingComponent.update(imageGraphics);
  107.  
  108.                     //Draw it to the screen
  109.                     g.drawImage(img, icBounds.x - myBounds.x, icBounds.y - myBounds.y, null);
  110.  
  111.                     imageGraphics.dispose();
  112.                 }
  113.  
  114.                 //No use in waiting for the garbage collector, we know it's garbage
  115.                 img.flush();
  116.  
  117.                 //Flush should call ImageRepresentation.dispose, but it is not,
  118.                 //so we'll have to make certain the finalize for the ImageRepresentation gets called
  119.                 //Since this is a big problem on the Macintosh, we'll only do it for them
  120.                 if (symantec.itools.lang.OS.isMacintosh())
  121.                 {
  122.                     System.gc();
  123.                     System.runFinalization();
  124.                 }
  125.             }
  126.         }
  127.     }
  128. }
  129.